#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=100;
const int N=100;
struct Edge{
	int v;
	int next;
};
Edge edge[M];

int node[N];
int stack[N],instack[N];
int Belong[N];
int Dfn[N],Low[N];
int n,m;
int Index,cnt_edge,top,Bcnt;

void add_edge(int u, int v){
	edge[cnt_edge].next = node[u];
	edge[cnt_edge].v = v;
	node[u] = cnt_edge++;
}

void Tarjan(int u){
	int i,j;
	int v;
	Dfn[u]=Low[u]=++Index;
	instack[u]=true;
	stack[++top]=u;
	for (i = node[u]; i != -1; i = edge[i].next){
		v=edge[i].v;
		if (!Dfn[v]){
			Tarjan(v);
			Low[u]=min(Low[u],Low[v]);
		}
		else if (instack[v])
				Low[u]=min(Dfn[v],Low[u]);
	}
	if (Dfn[u]==Low[u]){
		Bcnt++;
		do{
			j=stack[top--];
			instack[j]=false;
			Belong[j]=Bcnt;
		}while (j!=u);
	}
}

void solve(){
	int i;
	top=Bcnt=Index=0;
	memset(Dfn,0,sizeof(Dfn));
	memset(Low,0,sizeof(Low));
	for (i=1;i<=n;i++)
		if (!Dfn[i])
			Tarjan(i);
}

int main(){
	int j,k;
	cnt_edge=0;
	memset(node,-1,sizeof(node));
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>j>>k;
		add_edge(j,k);
	}
	solve();
	for(int i=1;i<=n;i++)
		cout<<Belong[i]<<" ";
}
